//
//  YTRegisterController.m
//  YUNT
//
//  Created by haha on 2017/11/11.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTRegisterController.h"
#import "YTTextField.h"
#import "YTLoginIconView.h"
#import "ZYXUser.h"
#import "ZYXUserNetManager.h"

@interface YTRegisterController ()
@property (weak, nonatomic) IBOutlet UITextField *accountTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
@property (weak, nonatomic) IBOutlet UIButton *liscenceButton;
@property (weak, nonatomic) IBOutlet YTTextField *authTextField;
@property (weak, nonatomic) IBOutlet UIButton *smscodeButton;
@property (weak, nonatomic) IBOutlet UIButton *authButton;
@property (weak, nonatomic) IBOutlet YTLoginIconView *iconView;

@end

@implementation YTRegisterController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = Language(@"注册");
    
    [self initSubviews];
}

- (void)initSubviews
{
    self.registerButton.layer.cornerRadius = 20;
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:Language(@"注册即同意")];
    
    [attString addAttribute:NSForegroundColorAttributeName
                      value:[UIColor blackColor]
                      range:NSMakeRange(0, attString.length)];
    
    NSMutableAttributedString *attString1 = [[NSMutableAttributedString alloc] initWithString:Language(@"软件许可及服务协议")];
    
    [attString1 addAttribute:NSForegroundColorAttributeName
                       value:[UIColor colorWithRed:162/255.0f green:69/255.0f blue:163/255.0f alpha:1.0f]
                       range:NSMakeRange(0, attString1.length)];
    
    [attString appendAttributedString:attString1];
    
    [attString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:NSMakeRange(0, attString.length)];
    
    [self.liscenceButton setAttributedTitle:attString forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)codeButtonAction:(UIButton *)sender
{
    
}

- (IBAction)smsButtonAction:(UIButton *)sender
{
    NSString *mobile = _accountTextField.text;
    
    if (mobile.length < 1)
    {
        [KeyWindow makeToast:Language(@"账号不能为空")];
        
        return;
    }
    
    [ZYXUserNetManager userRegisterAuthAccount:[NSString stringWithFormat:@"86%@",mobile] Success:^(NSDictionary *data, NSInteger status) {
        NSLog(@"%@",data);
    } Fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (IBAction)registerButtonAction:(UIButton *)sender
{
    NSString *mobile = _accountTextField.text;
    
    NSString *authCode = _authTextField.text;
    
    NSString *password = _passwordTextField.text;
    
    if (mobile.length < 1 || authCode.length < 1 || password.length < 1)
    {
        [KeyWindow makeToast:Language(@"输入内容不能为空")];
        
        return;
    }
    
    [ZYXUserNetManager userRegisterAccount:[NSString stringWithFormat:@"86%@",mobile] Auth:authCode Pw:password Success:^(NSDictionary *data, NSInteger status) {
         NSLog(@"%@",data);
    } Fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
